package com.ymx.darling.type;

import java.io.InputStream;
import java.sql.*;

public class InputStreamHandler implements TypeHandler<InputStream> {
    @Override
    public InputStream getResult(ResultSet resultSet, int columIndex) throws SQLException {
        return this.toInputStream(resultSet.getBlob(columIndex));
    }

    private InputStream toInputStream(Blob blob) throws SQLException {
        return blob == null ? null : blob.getBinaryStream();
    }

    @Override
    public void setParameter(PreparedStatement statement, InputStream value, int index) throws SQLException {
        statement.setBlob(index, value);
    }
}
